//
//  ViewController.m
//  testJSON
//
//  Created by Kluth on 2019/11/21.
//  Copyright © 2019 Kluth. All rights reserved.
//

#import "ViewController.h"
#import "Status.h"
#import "MJExtension.h"
#import "StatusResult.h"
#import "Ad.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [StatusResult mj_setupObjectClassInArray:^NSDictionary *{
        return @{
                   @"statuses" : @"Status",
                   // @"statuses" : [Status class],
                   @"ads" : @"Ad"
                   // @"ads" : [Ad class]
               };
    }];
    // Equals: StatusResult.m implements +mj_objectClassInArray method.

    NSDictionary *dict = @{
        @"statuses" : @[
                          @{
                              @"text" : @"Nice weather!",
                              @"user" : @{
                                  @"name" : @"Rose",
                                  @"icon" : @"nami.png"
                              }
                          },
                          @{
                              @"text" : @"Go camping tomorrow!",
                              @"user" : @{
                                  @"name" : @"Jack",
                                  @"icon" : @"lufy.png"
                              }
                          }
                      ],
        @"ads" : @[
                     @{
                         @"image" : @"ad01.png",
                         @"url" : @"http://www.ad01.com"
                     },
                     @{
                         @"image" : @"ad02.png",
                         @"url" : @"http://www.ad02.com"
                     }
                 ],
        @"totalNumber" : @"2014"
    };
    
    // JSON -> StatusResult
    StatusResult *result = [StatusResult mj_objectWithKeyValues:dict];

    NSLog(@"totalNumber=%@", result.totalNumber);
    
    for (Status *status in result.statuses) {
        NSString *text = status.text;
        NSString *name = status.user.name;
        NSString *icon = status.user.icon;
        NSLog(@"text=%@, name=%@, icon=%@", text, name, icon);
    }
    // text=Nice weather!, name=Rose, icon=nami.png
    // text=Go camping tomorrow!, name=Jack, icon=lufy.png

    // Printing
    for (Ad *ad in result.ads) {
        NSLog(@"image=%@, url=%@", ad.image, ad.url);
    }
    // image=ad01.png, url=http://www.ad01.com
    // image=ad02.png, url=http://www.ad02.com
}
-(void)test1{
    NSDictionary *dict = @{
           @"text" : @"Agree!Nice weather!",
           @"user" : @{
               @"name" : @"Jack",
               @"icon" : @"lufy.png"
           },
           @"retweetedStatus" : @{
               @"text" : @"Nice weather!",
               @"user" : @{
                   @"name" : @"Rose",
                   @"icon" : @"nami.png"
               }
           }
       };
       
       Status *status = [Status mj_objectWithKeyValues:dict];
       
       NSString *text = status.text;
       NSString *name = status.user.name;
       NSString *icon = status.user.icon;
       
       
       NSString *text2 = status.retweetedStatus.text;
       NSString *name2 = status.retweetedStatus.user.name;
       NSString *icon2 = status.retweetedStatus.user.icon;
       NSLog(@"text2=%@, name2=%@, icon2=%@", text2, name2, icon2);
       
       NSLog(@"%@%@%@",text,name,icon);
}

@end
